import request from '@/utils/request'

// 查询好友列表
export function listContactUser(query) {
  return request({
    url: '/sys-user/contact',
    method: 'get',
    params: query
  })
}

// 获取会话列表
export function listChat(data) {
  return request({
    url: '/im/chat/list',
    method: 'get',
    params: data
  })
}

// 创建会话
export function saveChat(data) {
  return request({
    url: '/im/chat',
    method: 'post',
    data: data
  })
}

// 获取会话详情
export function getChat(id) {
  return request({
    url: '/im/chat/' + id,
    method: 'get'
  })
}

// 移除会话
export function removeChat(id) {
  return request({
    url: '/im/chat/' + id,
    method: 'delete'
  })
}

// 获取聊天内容
export function listMessage(data) {
  return request({
    url: '/im/chat/message/page',
    method: 'get',
    params: data
  })
}

// 发送消息
export function sendMessage(data) {
  return request({
    url: '/im/message/send',
    method: 'post',
    data: data
  })
}

// 已读消息
export function readMessage(chatNumber, receiver) {
  let data = {
    "chatNumber": chatNumber,
    "receiver": receiver
  }
  return request({
    url: '/im/chat/message/read',
    method: 'put',
    data: data
  })
}

// 撤回消息
export function cancelMessage(id) {
  return request({
    url: '/im/chat/message/' + id,
    method: 'delete'
  })
}

